<?php


// 连接数据库
$conn=false;

try {
	//连接数据库 参数四（持久连接）：array(PDO::ATTR_PERSISTENT => true)
	$conn = new PDO("mysql:host=localhost;port=3306;dbname=blogs21", "root", "123456");
	//设置字符集
	$conn->query("set names utf8");


} catch (PDOException $ex) {
	die("不能连接数据库".$ex);
}

$username = 'admin';
$password = "12345611"; 


$sql = "select * from users where username=:username and password=:password";
echo $sql."<br/>";

// 预处理sql
$stmt = $conn->prepare($sql);

// 绑定参数
$stmt->bindParam(":username", $username);
$stmt->bindParam(":password", $password);

// 执行sql语句
$stmt->execute();

// 获取一行数据
$row = $stmt->fetch();
// var_dump($row);

// 判断是否获取到
if($row){
	echo "欢迎:".$row['username']."，登录成功";
} else {
	echo "登录失败";
}


